<template>
  <article class="article" :class="{ mobile: isMobile }">
    <router-link class="article-thumbnail" :to="`/article/${article.id}`">
      <!-- <span class="item-origin" :class="{ self: isOriginal, other: isReprint, hybrid: isHybrid }">
        <template v-if="isOriginal">原创</template>
        <template v-else-if="isReprint">转载</template>
        <template v-elseif="isHybrid">混合</template>
      </span>-->
      <img
        :src="article.thumb"
        :alt="article.title"
        loading="lazy"
        class="thumbnail"
        width="240"
        height="160"
      />
    </router-link>
    <div class="article-content">
      <h3 class="title">
        <router-link :to="`/article/${article.id}`" :title="article.title">{{ article.title }}</router-link>
      </h3>
      <div class="summary">{{ article.description }}</div>
      <div class="article-meta">
        <span>
          <i class="iconfont icon-time" />
          <span>{{ timeAgo(article.create_at) }}</span>
        </span>
        <span>
          <i class="iconfont icon-eye" />
          <span>{{ article.views || 0 }}</span>
        </span>
        <span>
          <i class="iconfont icon-comment" />
          <span>{{ article.comments || 0 }}</span>
        </span>
        <span>
          <i class="iconfont icon-zan" :class="{ liked: isLiked }" />
          <span>{{ article.likes || 0 }}</span>
        </span>
        <!-- <span class="tags">
          <i class="iconfont icon-tag"></i>
          <span>{{ article.tags }}</span>
        </span> -->
        <span>
          <i class="iconfont" />
          {{ article.category && article.category.length && article.category[0].name }}
        </span>
      </div>
    </div>
  </article>
</template>

<script>
import { useEnhandle } from "@/enhandle";
import { timeAgo } from "@/transforms/moment";

export default {
  name: "article-list-item",
  props: {
    article: Object,
  },
  data() {
    return {
      isLiked: false,
    };
  },
  setup() {
    const { isMobile } = useEnhandle();
    return {
      isMobile,
      timeAgo,
    };
  },
};
</script>

<style lang="scss" scoped>
.article {
  position: relative;
  padding: 20px 0;
  margin-bottom: 1em;
  border-bottom: 1px solid #eee;
  overflow: hidden;
  &:hover .thumbnail {
    transform: scale(1.075);
  }
  .article-thumbnail {
    position: relative;
    float: left;
    display: block;
    margin-right: 10px;
    overflow: hidden;
    border-radius: 6px;
    width: 240px;
    height: 160px;
    .thumbnail {
      transition: 0.4s ease-in-out;
    }
  }
  .article-content {
    position: relative;
    float: right;
    width: calc(100% - 250px);
    height: 160px;
    .title {
      margin: 0;
      font-weight: 500;
      vertical-align: middle;
      @include text-overflow();
      a {
        transition: 0.3s;
        vertical-align: middle;
        @include text-overflow();
      }
    }
    .summary {
      display: -webkit-box;
      -webkit-line-clamp: 4;
      -webkit-box-orient: vertical;
      text-indent: 2em;
      margin: 10px auto;
      height: 90px;
      overflow: hidden;
      color: $text;
      line-height: 23px;
      font-size: 14px;
      word-break: break-word;
      text-overflow: ellipsis;
    }
    .article-meta {
      display: flex;
      justify-content: space-between;
      height: 2em;
      line-height: 2em;
      align-items: baseline;
      overflow: hidden;
      font-size: 12px;
      white-space: nowrap;
      text-overflow: ellipsis;
      word-wrap: normal;
      > span {
        color: $text;
      }
      .iconfont {
        margin-right: 0.3em;
      }
    }
  }

  &.mobile {
    display: block;
    margin-bottom: 1em;
    .article-thumbnail {
      width: 100%;
      margin-right: 0;
      .thumbnail {
        width: 100%;
      }
    }
    .article-content {
      position: relative;
      width: 100%;
      .title {
        margin: 8px 0;
        a {
          vertical-align: middle;
        }
      }
      .summary {
        font-size: 13px;
      }
      .article-meta {
        display: flex;
        justify-content: space-between;
        color: #999;
      }
      .detail-btn {
        display: block;
        margin-top: 10px;
        padding: 8px 6px;
        text-align: center;
        border-radius: 4px;
        color: #fff;
        background-color: #1890ff;
      }
    }
  }
}
</style>
